import os
import re
#num = 1

for file in os.listdir(path='/home/unionsys/Pictures/JR/labels/val/'):
    print(file)
    with open('/home/unionsys/Pictures/JR/labels/val/'+file, "r+", encoding='utf-8') as f:
    # readlines()：读取文件全部内容，以列表形式返回结果
        data = f.readlines()
        for item in data:
            print(item)
            text = list(item)    #将字符串转换为列表，列表的每一个元素为一个字符
            if (text[0] == '2'):
                text = ''.join(text)     #将列表重新连接为字符串
                print(text)
                newf = open('/home/unionsys/Pictures/JR/labels/'+file, 'a', encoding='utf-8')
                newf.write(text)
                newf.close()
